// pages/mine/prizes/index.js
const app=getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    setWidthH: "",//初始化设置宽高
    isAddrShow: "none",//显示输入地址框
    isListShow: "block",//显示列表
    allres: [],
    jiangpId: "",
    named: '',
    phoned: "",
    prov: "",
    addr: "",
    insteadp: "",
    havenodata:false,
    showDetai: [],
    pagei:1,
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options){
    this.getZhongJ();
  },  
  copythis: function (e) {
    var str = e.target.dataset.ma;
    wx.setClipboardData({
      data: str,
      success: function (res) {
        wx.showToast({ title: "复制成功"});
      }
    });
  },
  getZhongJ:function(){
    //请求中奖纪录数据
    var that = this;
    app.apiRequest({
      url: "/reward/queryListBy",
      // data: { },
      success: function (res) {
        // console.log("中奖记录：", res);
        var tres=res.data.data,resi=0;
        var tresd=[];
        var tend=[];
        //先根据活动分割数据
        while(true){
          if (tres.length == 0) { break; }
          tresd[resi] = []
          tresd[resi][0] = tres.shift()
          if(tresd[resi][0]){
            let tmpu = tresd[resi][0].url, tstr = tresd[resi][0].des;
            let tjtype = "no";
            if (tmpu && tmpu.indexOf(".") == -1) { tjtype = "yes"; }
            else if (tstr && tstr.indexOf("【跳转】") > -1) {
              tjtype = "yes";
            }
            tresd[resi][0].jumpTarget = tjtype;
          }
          // console.log("处理的数据1",tresd)
          for(let i=tres.length-1;i>=0;i--){
            if(tresd[resi][0].activityName==tres[i].activityName){
              var tmpu=tres[i].url,tstr=tres[i].des;
              var tjtype="no";
              if(tmpu && tmpu.indexOf(".")==-1){tjtype="yes";}
              else if (tstr && tstr.indexOf("【跳转】")>-1){
                tjtype="yes";
              }             
              tres[i].jumpTarget = tjtype;
              console.log(tres)
              tresd[resi].push(tres[i]);
              tres.splice(i,1);
            }
          }
          resi++;
        }
        // console.log(tresd)
        //生成点击控制数组
        var tall = [];
        for(let i in tresd){
          var tar = ["", "",""]
          tall.push(tar);}
        //按照活动类别分类
        for(let i=0;i<tresd.length;i++){
          tend[i]={}
          tend[i].good=[]
          tend[i].card = []
          tend[i].menp = []
          var tmpa = tresd[i];
          for(let j=0;j<tmpa.length;j++){
            if (tmpa[j].prizeType==1){
              tend[i].menp.push(tmpa[j])
            }else if (tmpa[j].prizeType == 2) {
              tend[i].good.push(tmpa[j])
            }else{
              tend[i].card.push(tmpa[j])
            }
          }          
        }
        // console.log(tall)
        that.setData({
          showDetai: tall
        });
        
        if (tend.length > 0) {
          that.data.pagei += 1;
        } else {
          that.setData({
            havenodata: true
          });
          return;
        }        
        that.setData({
          allres: that.data.allres.concat(tend)
        });
      }
    });
    return;
    app.apiRequest({
      url: "/my/findUserByToken",
      success: res => {
        var tid = res.data.data.id
        
      }
    })
  },
  showOrHide:function(e){    
    var vid=parseInt(e.target.dataset.ind),//第一个坐标
        hid=parseInt(e.target.dataset.ide);//第二个坐标    
    var tar = this.data.showDetai
    // console.log(vid, hid, tar[vid][hid])
    if (tar[vid][hid] == "") { tar[vid][hid] = "new_isShow";}
    else { tar[vid][hid] = "";}    
    this.setData({
      showDetai:tar
    });
  },
  isJumpthis:function(e){
    var str = e.target.dataset.ma;    
    if(str.indexOf('.')>-1){      
      app.globalData.tmpAllUrl=str;
      wx.navigateTo({
        url: "../../webview/webview?url=" + str
      });
    }else{
      wx.navigateToMiniProgram({
        appId: str,
        // path:'',//跳转的页面
        extraData: {
          form:"粉鲸饭团"
        },
        success: function () { }
      })
    }
  }
})